package com.beinhospital_sw21_h2_05.beinhospitalsw21h205.controller;

import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Doctor;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Linshi2;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Medicine;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.service.DoctorService;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.utils.PageBean;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 控制器类，处理与医生（Doctor）相关的HTTP请求
 */
@CrossOrigin
@Slf4j
@RestController
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    /**
     * 医生分页查询
     * @param page 页码，默认为1
     * @param pageSize 每页大小，默认为10
     * @param doctorName 医生姓名，可选
     * @return 分页查询结果
     */
    @GetMapping("/doctor")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String doctorName) {
        log.info("医生分页查询：{}，{},{}", page, pageSize, doctorName);
        PageBean pageBean = doctorService.page(page, pageSize, doctorName);
        return Result.success(pageBean);
    }

    /**
     * 根据医生ID删除医生
     * @param doctorID 医生ID
     * @return 操作结果
     */
    @DeleteMapping("/doctor/{doctorID}")
    public Result delete(@PathVariable Integer doctorID) {
        log.info("根据id删除医生：{}", doctorID);
        doctorService.delete(doctorID);
        return Result.success();
    }

    /**
     * 新增医生
     * @param linshi2 包含新增医生信息的对象
     * @return 操作结果
     */
    @PostMapping("/doctor")
    public Result insert(@RequestBody Linshi2 linshi2) {
        log.info("新增医生：{}", linshi2);
        doctorService.add(linshi2);
        return Result.success();
    }

    /**
     * 编辑医生信息
     * @param linshi2 包含编辑后的医生信息的对象
     * @return 操作结果
     */
    @PutMapping("/doctor")
    public Result update(@RequestBody Linshi2 linshi2) {
        log.info("编辑医生：{}", linshi2);
        doctorService.update(linshi2);
        return Result.success();
    }
}
